<template>
{{#if ctrl.psSysPFPlugin}}
    {{> @macro/plugins/widget/widget-use.hbs appPlugin=ctrl.psSysPFPlugin}}
{{else}}
  <AppExpBar 
        :class="classNames">
{{#if ctrl.showTitleBar}}
    <template #titleBar>
      <div class="control-header__left__caption">
  {{#if ctrl.psSysImage}}
    {{#if ctrl.psSysImage.imagePath}}
        <img src="{{ctrl.psSysImage.imagePath}}"/>
    {{/if}}
    {{#if ctrl.psSysImage.cssClass}}
        <i class="{{ctrl.psSysImage.cssClass}}"></i>
    {{/if}}
  {{/if}}
        <span class="text">\{{model.title}}</span>
      </div>
    </template>
{{/if}}
<template #quickGroup>
  <slot name="quickGroup"></slot>
</template>
{{#if ctrl.enableSearch}}
    <template #quickSearch>
      {{> @macro/common/quick-search.hbs}}
    </template>
{{/if}}
{{#ctrl.ctrls}}
  {{#eq controlType 'TOOLBAR'}}
    <template #toolbar>
      <AppToolbar
        name="toolbar"
        :items="toolbarItems"
        @item-click="(name: string, event: MouseEvent, logic: any) => { handleToolbarItemClick(controller, name, event, logic) }">
      </AppToolbar>
    </template>
  {{/eq}}
{{/ctrl.ctrls}}
    <template #default>
    {{#ctrl.psControls}}
        {{#eq controlType "CALENDAR"}}
        <{{codeName}}Calendar
            ref="xDataControl"
            name="{{name}}"
            :actions="{
              createAction: '{{#and createPSControlAction createPSControlAction.psAppDEMethod}}{{createPSControlAction.psAppDEMethod.codeName}}{{else}}Create{{/and}}',
              fetchAction: '{{#and fetchPSControlAction fetchPSControlAction.psAppDEMethod}}{{fetchPSControlAction.psAppDEMethod.codeName}}{{else}}FetchDefault{{/and}}',
              removeAction: '{{#and removePSControlAction removePSControlAction.psAppDEMethod}}{{removePSControlAction.psAppDEMethod.codeName}}{{else}}Remove{{/and}}',
              updateAction: '{{#and updatePSControlAction updatePSControlAction.psAppDEMethod}}{{updatePSControlAction.psAppDEMethod.codeName}}{{else}}Update{{/and}}'
            }"                
            :context="context"
            :viewParams="viewParams"
            :openView="openView"
            :newView="newView"
            :closeView="closeView"
            :selectFirstDefault="true"
            :pViewCtx="store.viewCtx"
            @ctrl-init="(name, ability) => { handleCtrlInit(controller, name, ability) }"
            @ctrl-action="(name, action, data) => { handleCtrlAction(controller, name, action, data) }"
            @ctrl-destroy="(name, data) => { handleCtrlDestroy(controller, name, data) }"
        ></{{codeName}}Calendar>
        {{/eq}}
    {{/ctrl.psControls}}
    </template>
    </AppExpBar>
{{/if}}
</template>
<script setup lang="ts">
// 基于template/src/widgets/\{{appEntities}}/\{{ctrls@CALENDAREXPBAR}}-calendar-exp-bar/\{{spinalCase ctrl.codeName}}-calendar-exp-bar.vue.hbs生成
{{> @macro/plugins/widget/widget-import.hbs ctrl=ctrl}}
{{#ctrl.psControls}}
    {{#eq controlType "CALENDAR"}}
import {{codeName}}Calendar from '@widgets/{{spinalCase appEntity.codeName}}/{{spinalCase codeName}}-calendar/{{spinalCase codeName}}-calendar.vue';
    {{/eq}}
    {{#eq controlType 'TOOLBAR'}}
import { AppToolbar } from '@components/widgets/toolbar';
    {{/eq}}    
{{/ctrl.psControls}}
import { model{{#ctrl.ctrls}}{{#eq controlType 'TOOLBAR'}}, toolbarItems{{/eq}}{{/ctrl.ctrls}} } from './{{spinalCase ctrl.codeName}}-calendar-exp-bar-model';
import { AppExpBar} from '@components/widgets/exp-bar';
import { CalendarExpBarActionType, CalendarExpBarController, IContext, ICalendarExpBarAbility, ICalendarExpBarControllerParams, ICalendarExpBarStore, IParam, ICalendarExpBarController, ILoadingHelper, createUUID, IViewCtx } from '@/core';
import { 
  useNavParamsBind, 
  useEventBind, 
  getExpBarClassNames, 
{{#ctrl.ctrls}}
  {{#eq controlType 'TOOLBAR'}}
  handleToolbarItemClick,
  {{/eq}}
{{/ctrl.ctrls}}
{{#and ctrl.parent ctrl.parent.enableQuickGroup ctrl.parent.quickGroupPSCodeList}}
  handleQuickGroupValueChange,
{{/and}}
{{#if ctrl.enableSearch}}
  handleQuickSearch,
{{/if}}  
  handleCtrlInit, 
  handleCtrlAction, 
  handleCtrlDestroy 
} from '@/hooks/use-ctrl';

// 输入参数
{{> @macro/widgets/ctrl/ctrl-props.hbs
    props="openView?: Function;
    newView?: Function;
    "
}}

// emit
{{> @macro/common/emit.hbs name="ctrl" actionType="CalendarExpBarActionType" ability="ICalendarExpBarAbility"}}    

const classNames = computed(() => {
    return getExpBarClassNames(model, props);
});

const controlID = 'id' + createUUID();    

const params: ICalendarExpBarControllerParams<CalendarExpBarActionType, ICalendarExpBarAbility> = {
    name: props.name,    
    model,
    evt,
    controlID,    
    pLoadingHelper: props.pLoadingHelper,      
    openView: props.openView,
    newView: props.newView,
    closeView: props.closeView,
    pViewCtx: props.pViewCtx,
    handler: (data: ICalendarExpBarStore) => { return reactive(data); }
};

// 控制器
{{> @macro/common/controller.hbs name="ctrl" IController="ICalendarExpBarController" store="ICalendarExpBarStore" ability="ICalendarExpBarAbility" controller="CalendarExpBarController"}}
</script>